using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web;
using Microsoft.SharePoint.Administration;
using System.Diagnostics;
using System.Reflection;
using Microsoft.SharePoint;
using System.Web.Configuration;
using System.Configuration;
using System.Web.Security;
using Microsoft.SharePoint.Utilities;

namespace CKS.InternetExtranet
{
    public class Utils
    {
        
        public static void LogError(string errorMessage, string errorCategory)
        {
            // log error to ULS log
            TraceProvider.WriteTrace(0, TraceProvider.TraceSeverity.CriticalEvent, Guid.NewGuid(), Assembly.GetExecutingAssembly().FullName, "InternetExtranetEdition", errorCategory, errorMessage);
        }

        public static void LogError(Exception ex)
        {
            // create error message
            string errorMessage = ex.Message + " " + ex.StackTrace;
           
            // add any inner exceptions
            Exception innerException = ex.InnerException;
            while (innerException != null)
            {
                errorMessage += "Inner Error: " + innerException.Message + " " + innerException.StackTrace;
                innerException = innerException.InnerException;
            }

            // log error
            LogError(errorMessage, ex.GetType().ToString());
        }

        public static void LogError(Exception ex, bool transferToErrorPage)
        {
            LogError(ex);
            SPUtility.TransferToErrorPage(ex.Message);
        }
    }
}
